package com.example.generator.base;


import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;

/**
 * @author Jiamingzhen
 * @Date 2021/4/23 10:03
 * @ClassName GeneratorConfig
 * @Introduce 全局配置
 */
public class GeneratorConfig extends AbstractGeneratorConfig{
    private GenConfig genConfig;

    public GeneratorConfig(GenConfig genConfig) {
        this.genConfig = genConfig;
    }
    @Override
    protected void config() {
        dataSourceConfig();
        globalConfig();
        strategyConfig();
        packageConfig();
        templateConfig();
    }
    protected void dataSourceConfig(){
        dsc.setUrl("jdbc:mysql://120.78.66.65:3306/jiamz?serverTimezone=UTC&useUnicode=true&useSSL=false&characterEncoding=utf8");
        // dsc.setSchemaName("public");
        dsc.setDriverName("com.mysql.cj.jdbc.Driver");
        dsc.setUsername("root");
        dsc.setPassword("Jiamingzhen.520");
    }
    protected void globalConfig() {
        String projectPath = System.getProperty("user.dir");
        gc.setOutputDir(projectPath + "/src/main/java");
        gc.setAuthor("Jiamingzhen");
        gc.setOpen(false);
        gc.setFileOverride(true);
        gc.setEnableCache(false);
        gc.setBaseResultMap(true);
        gc.setBaseColumnList(true);
    }
    protected void strategyConfig() {
        //驼峰命名
        strategy.setNaming(NamingStrategy.underline_to_camel);
        strategy.setColumnNaming(NamingStrategy.underline_to_camel);
        strategy.setEntityLombokModel(true);
        strategy.setEntityTableFieldAnnotationEnable(true);
        strategy.setRestControllerStyle(true);
        strategy.setControllerMappingHyphenStyle(true);
        // 公共父类，自己的父类控制器,没有就不用设置
        strategy.setSuperControllerClass("");
        // 写于父类中的公共字段，此字段不会在实体类中生成
        strategy.setSuperEntityClass("com.example.base.BaseEntity");
        strategy.setSuperEntityColumns(new String[]{"createDate","isDel"});
        //设置表名
        //"表名，多个英文逗号分割"
        strategy.setInclude(genConfig.getTableName());

        strategy.setTablePrefix(pc.getModuleName()+"_");
    }
    protected void packageConfig() {
        pc.setModuleName(genConfig.getTableName());
        pc.setParent("com.example");
    }
    protected void templateConfig() {
        templateConfig.setController("/templates/temp/controller.java");
        templateConfig.setService("/templates/temp/service.java");
        templateConfig.setServiceImpl("/templates/temp/serviceImpl.java");
        templateConfig.setXml(null);
    }
}
